- 
                Notifications
    
You must be signed in to change notification settings  - Fork 9.4k
 
12073: ProductRepository fails to load product with camelcase SKU #12169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| } | ||
| 
               | 
          ||
| if (!isset($this->instances[$sku])) { | ||
| throw new NoSuchEntityException(__('Requested product doesn\'t exist')); | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code completely duplicates previous condition.
What is this issue all about? I see a trim but don't see any strtolower in logic like $this->instances[$product->getSku()][$cacheKey] = $product;.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@orlangur, ok, let me explain. We have product with sku "Test". We try to use "get" method of repository to get product with sku "test". Method resourceModel->getIdBySku($sku) will return to us id of "Test" and in $this->instances it put the sku "Test". So after trim we are checking if we have $this->instances["test"] and we don't have it, because we have $this->instances["Test"].
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@orlangur, what how? Trimming isn't my logic). It was before my changes. I only check if product sku("Test") is the same as requested sku("test"). And if it isn't the same exception will be thrown.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, let me reword. Why product is stored with lower-cased SKU in the first place?
We must find a root cause so that exception will be thrown from line 240 instead of adding more exceptions throwing.
| 
           @orlangur, any updates on it?  | 
    
| 
           @orlangur, ping.  | 
    
| } | ||
| 
               | 
          ||
| if (!isset($this->instances[$sku])) { | ||
| throw new NoSuchEntityException(__('Requested product doesn\'t exist')); | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, let me reword. Why product is stored with lower-cased SKU in the first place?
We must find a root cause so that exception will be thrown from line 240 instead of adding more exceptions throwing.
| 
           For the record, this PR will not fix the issue that it purports to fix (#12073). It will simply result in an exception rather than an error if the condition described in #12073 is met. However it will not allow a SKU with a mixed-case to get loaded via the product repository. See this comment for more context.  | 
    
          
 
 Actually, not, but I do agree with comment you referring to that it is better to fix regression introduced.  | 
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a regression in 2.2.0, still present as of 2.2.2. The problem was introduced right here: cb3b5d1#diff-ff4893a5628d34910295bae32fbcddfdL241
Just change implementation of cacheProduct in such a way that we pass both productId and sku instead of obtaining them from product instance.
The test should enforce that we can actually load product by such SKU.
          
 This sounds obscure, because we have two different functions   | 
    
          
 That's the point. It should work this way. Just rework implementation of   | 
    
| 
           @orlangur, Why do we need to cache "test" and "Test" if we have only only one product? It is obscure. This is misleading and I don't think this is right. 
  | 
    
          
 Please reword a bit.   | 
    
| 
           You are right that  So, I think it should throw exception. If I have product with sku "Test", so why when I ask product with sku "teSt" it should return the same product? We don't have product with sku "teSt", we have only with sku "Test". This is misleading for me.  | 
    
| 
           @RomaKis because that's how it worked before we introduced caching in product repository. Another case I didn't mention is that MySQL does not distinguish not just lower/upper case but also е and ё, o and ö, a and ã and so on. There is no need to introduce any additional restrictions if we can keep the things consistent without them.  | 
    
| 
           If it worked in such way it didn't mean that it worked right. I remain at my mind - Magento shouldn't cache products with non-existent sku. As I mentioned it is misleading. You can  If you don't accept this implementation - so close this PR )  | 
    
| 
           Such case is not nonexistent SKU in fact and is a behavior explicitly requested in #12169 (comment).  | 
    
| 
           @orlangur What is the reason for rejecting the pull request? The issue is from Nov 2017 and still not fixed. Is there a plan in place to address this issue or it is up to the community and their availability to fix it?  | 
    
| 
           @mcspronko because a proper implementation approach is performed in #14019. It needs some assistance with test but no time to look into it yet. Cc: @maximgubar  | 
    
ProductRepository fails to load product with camelcase SKU
Fixed Issues (if relevant)
Manual testing scenarios
Expected result
Contribution checklist